package csu.web.mypetstore.web.servlet;

import csu.web.mypetstore.domain.Account;
import csu.web.mypetstore.domain.Cart;
import csu.web.mypetstore.domain.LineItem;
import csu.web.mypetstore.domain.Order;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Iterator;

public class UpdateOrderServlet extends HttpServlet {
    private static final String CART_FORM = "/WEB-INF/jsp/order/viewOrder.jsp";

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Order order = new Order();
        //获取account和cart
        Account account = (Account) session.getAttribute("account");
        Cart cart = (Cart) session.getAttribute("cart");

        order.initOrder(account, cart);

        Iterator<LineItem> orderItems = order.getLineItems().iterator();
        while (orderItems.hasNext()) {
            LineItem lineItem = orderItems.next();
            System.out.println("Product: " + lineItem.getProductName());
            System.out.println("Quantity: " + lineItem.getQuantity());
            System.out.println("Price: " + lineItem.getPrice());
        }
    }

}
